<?PHP

		$deleted=FALSE;
		$post=$_POST;
		ini_set("memory_limit","128M");

		$media = new media;
		$media->post=$post;
		$media->files=$_FILES;
		$media->input['raw']='upload_image';
		
		if($post['resize_image']==1 && !empty($post['resize_x']) && !empty($post['resize_y']))
		{

			printmessage('Resizing Image to: '.$post['resize_x'].' x '.$post['resize_y']);

			$media->input['resize_x']=$post['resize_x'];
			$media->input['resize_y']=$post['resize_y'];
			$media->mode='resize_image';	
		}
		
$image_data=$media->process_image();		
		
if($_POST['delete']=='delete')
{
		mp('delete');
		rp($_GET['id']);
		
		delete_sql($table,$id,$_GET['id'],FALSE);
	
		printmessage('Successfully Deleted');
		$deleted=TRUE;
}
else if($_POST['cmd']=='add' && !empty($_POST[$catch]))
{
		$post=process_default_serialized_values($post);
		$post['thumb']=$image_data['thumb'];
		$post['image']=$image_data['image'];
		process_sql_post($post,'media','add',NULL,NULL);
		$post['media']=mysql_insert_id();
		process_sql_post($post,$table,'add',NULL,NULL);
		printmessage('Successfully Added');
		
		
}
else if($_POST['cmd']=='edit')
{

		$post=process_default_serialized_values($post);
		process_sql_post($post,$table,'update',$id,$_GET[$id]);
		process_sql_post($post,'media','update','id',$post['media']);
		printmessage('Successfully Modified');
}

if($_GET['cmd']=='edit' && isset($_GET[$id]) && !$deleted)
{
		$f=get_data_form($table,$id);
		print_r($f['3']);
		//echo $f['media'];
		$w[0]='id';
		$w[1]=$f['3'];
		$w[2]='=';
		$where[]=$w;
		
		$x=get_sql('media','id',$where,NULL);
		$i=current($x);
		print_r($i);
		$e=array_merge((array)$f,(array)$i);
	if($e['serial'] == 'N;' || empty($e['serial']) )
	{
	
			
	}
	else
	{
			$serial=unserialize($e['serial']);
			$e=array_merge($e,$serial);	
	}
	
	
}
else
{
		$_GET['cmd']='add';
}

?>